package com.fyzk.activity.user;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;

import com.fyzk.bean.ChaseListItem;
import com.fyzk.interfaces.MoreInterface;
import com.fyzk.interfaces.ReTryInterface;
import com.fyzk.interfaces.UpdateInterface;
import com.tyjc.lottery.R;
import com.fyzk.view.MsgListView;

import java.util.ArrayList;

/**
 * 追号记录列表
 */
public class ZhuihaoRecordListView extends FrameLayout{

    private String TAG = this.getClass().getSimpleName();

    NetProgressView netProgressView;
    MsgListView listViewExt;
    ZhuiHaoListAdapter listAdapter;
    public ArrayList<ChaseListItem> infos;
    private Context context;


    public ZhuihaoRecordListView(Context context, AttributeSet attrs,
                                 int defStyle) {
        super(context, attrs, defStyle);
        this.context = context;
        init();
        // TODO Auto-generated constructor stub
    }

    public ZhuihaoRecordListView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        // TODO Auto-generated constructor stub
    }

    public ZhuihaoRecordListView(Context context) {
        this(context, null);
        // TODO Auto-generated constructor stub
    }

    private void init() {
        View.inflate(context, R.layout.layout_recordlist, this);
        netProgressView = (NetProgressView) findViewById(R.id.recordProgressView);
        listViewExt = (MsgListView) findViewById(R.id.recordlist);
        infos = new ArrayList<ChaseListItem>();
        listAdapter = new ZhuiHaoListAdapter(context, infos);
        listViewExt.setAdapter(listAdapter);
    }

    ZhuiHaoListAdapter.OnCancelClickListener listener;

    public void setOnCancelClickListener(ZhuiHaoListAdapter.OnCancelClickListener listener) {
        this.listener = listener;
        listAdapter.setOnCancelClickListener(listener);
    }

    /**
     * 初始化记录列表
     *
     * @param infos
     */
    public void initRecordList(ArrayList<ChaseListItem> infos) {
        if (infos.size() > 0) {
            netProgressView.setVisibility(View.GONE);
            if (null != infos) {
                this.infos.clear();
                this.infos.addAll(infos);
            }

            if (infos.size() < 20) {
                listViewExt.listMore.setClickable(false);
                listViewExt.listMore.setTextStr("无更多数据");
            } else {
                listViewExt.listMore.endNet();
            }

            listViewExt.onRefreshComplete();
            listAdapter.notifyDataSetChanged();
        }
    }

    /**
     * 为记录列表增加
     *
     * @param infos
     */
    public void addRecordInfos(ArrayList<ChaseListItem> infos) {
        netProgressView.setVisibility(View.GONE);
        if (null != infos) {
            this.infos.addAll(infos);
        }
        if (infos.size() < 20) {
            listViewExt.listMore.setClickable(false);
            listViewExt.listMore.setTextStr("无更多数据");
        } else {
            listViewExt.listMore.endNet();
        }
        listAdapter.notifyDataSetChanged();
    }

    public void updateFinish() {
        listViewExt.onRefreshComplete();
    }

    /**
     * 刷新列表
     *
     * @param infos
     */
    public void refrashInfos(ArrayList<ChaseListItem> infos) {
        netProgressView.setVisibility(View.GONE);
        this.infos.clear();
        if (null != infos) {
            this.infos.addAll(infos);
        }
        listAdapter.notifyDataSetChanged();
    }


    public void setMoreInterface(MoreInterface moreInterface) {
        listViewExt.setMoreInterface(moreInterface);
    }

    public void setUpdateInterface(UpdateInterface updateInterface) {
        listViewExt.setUpdateInterface(updateInterface);
    }

    public void showData() {
        netProgressView.setVisibility(View.VISIBLE);
        netProgressView.dismiss();

    }

    public void showLoading() {
        netProgressView.setVisibility(View.VISIBLE);
        netProgressView.waiting();
    }

    public void showNoneRecord(String message) {
        netProgressView.setVisibility(View.VISIBLE);
        netProgressView.noneRecord(message);
    }

    public void showFail(String message) {
        infos.clear();
        listAdapter.notifyDataSetChanged();
        netProgressView.setVisibility(View.VISIBLE);
        netProgressView.fail(message);
    }

    public void setRetryInterface(ReTryInterface reTry) {
        netProgressView.setRetryInterface(reTry);
    }



}
